package org.eraser.security.authentication.oidc;

import lombok.Builder;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 动态授权相关
 * Principal 表示用户或客户端/计算机的身份的对象。
 * Authentication 是 SpringSecurity 对 Principal 的实现。
 * GrantedAuthority 表示授予 Authentication 的权限。
 * <p>
 * SimpleGrantedAuthority 是对 GrantedAuthority 的实现。
 * JaasGrantedAuthority 是对 GrantedAuthority 的实现。Java Authentication and Authorization Service JRE提供
 * <p>
 * UsernamePasswordAuthenticationToken 是对 Authentication 的实现。
 * JaasAuthenticationToken 是对 Authentication 的实现。
 * <p>
 * 本类是对 SpringSecurity 中 User 类的实现
 * <p>
 * EndUser简称EU OIDC定义的“终端用户”的概念
 */
@Builder
public class EndUser implements UserDetails {

    private User user;

    public EndUser() {}

    public EndUser(User user) {
        this.user = user;
    }

    private User getUser() {
        return user;
    }

    private void setUser(User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return user.getAuthorities();
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getPassword();
    }

    @Override
    public boolean isAccountNonExpired() {
        return user.isAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return user.isAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return user.isCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return user.isEnabled();
    }


}
